package top.lywivan.web;

import top.lywivan.service.BrandService;
import top.lywivan.utils.BeanFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/deleteBrandById")
public class DeleteBrandByIdServlet extends HttpServlet {
    private BrandService brandService= BeanFactory.getBean(BrandService.class);
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String result="success";
        try {
            String id = request.getParameter("id");
            //String s = request.getReader().readLine();
            //System.out.println(s);
            brandService.deleteBrandById(Integer.parseInt(id));
        } catch (Exception e) {
            e.printStackTrace();
            result="error";
        }
        response.getWriter().write(result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
